These exercise cover the scales, statistics and themes of ggplot2 for Plotting in R.
Exercise 1 - Themes
Read in the cleaned patients dataset as we saw in ggplot2 course earlier (“patients_clean_ggplot2.txt”)
Set the global theme to use theme_bw(). Using the patient data set generate a scatter plot of BMI versus Weight. Add a color scale to the scatter plot based on the Pet variable. Use an additional geom to add an extra layer of a fit line to our scatterplot (use lm method). Lets also add a nice color palette of your choice from Colorbrewer, Paleteer or Viridis.
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
Take at least one element from each theme you just tried out and add it to our existing theme.
Use the + to update our plot to use the new theme
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Saving 7 x 5 in image
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 5 rows containing missing values or values outside the scale range
## (`geom_point()`).
Exercise 2 - External Packages
## Warning: namespace 'DESeq2' is not available and has been replaced
## by .GlobalEnv when processing object 'deseq_pca_example'
## PC1 PC2 group condition name
## sample1 -13.24423 22.0512418 A Ctrl sample1
## sample2 -14.40362 -13.8514994 A Ctrl sample2
## sample3 -14.79663 -2.9299797 A Ctrl sample3
## sample4 -15.12221 -9.4008058 A Mut sample4
## sample5 -14.78719 -0.2914010 A Mut sample5
## sample6 -13.77777 5.6896212 A Mut sample6
## sample7 13.68499 -2.4219808 B Ctrl sample7
## sample8 14.85294 3.9328670 B Ctrl sample8
## sample9 12.21286 -3.0234083 B Ctrl sample9
## sample10 16.25675 -5.6924350 B Mut sample10
## sample11 14.85222 0.9620356 B Mut sample11
## sample12 14.27188 4.9757444 B Mut sample12
## Aesthetic mapping:
## * `colour` -> `group`
## * `x` -> `PC1`
## * `y` -> `PC2`
deseq_replot <- deseq_pca_example
deseq_replot$layers <- NULL
deseq_replot <- deseq_replot + geom_point(aes(x=PC1, y=PC2, color=group, shape=condition)) + scale_fill_viridis_d() + ggtitle("PCA plot of DGE in A and B groups")Exercise 3 - Interactive Plots
## Warning in geom_point(aes(label = name)): Ignoring unknown aesthetics: label